Comparison Operators

The action of comparison is extremely important in programming. Here are the operators you can use to carry out those comparisons.


In [10]:
# Code to display an image!
from IPython.display import Image
Image("/home/mohsin/GitHub/pythonbootcampacm/Comparison Operators/table.png")


Out[10]:

In [13]:
2 == 2


Out[13]:
True

In [14]:
2 != 3


Out[14]:
True

In [15]:
2 != 2


Out[15]:
False

In [1]:
2 <= 3


Out[1]:
True

Chained Comparison Operators

If you completed the "Control Flow" section of the bootcamp, you have learned about "and" and "or" statements in Python. You can create expressions that render both words uneeded. While you will always use "and" along with "or", it is critical to understand all of the syntax.


In [7]:
# Normal
9 < 10 and 10 < 11


Out[7]:
True

In [8]:
# Chained
9 < 10 < 11


Out[8]:
True

In [9]:
# Alternate sign position
11 < 13 > 12
# Same as
11 <13 and 13 > 12


Out[9]:
True